package com.diudiutechnology.www.yadiudiu.util.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.diudiutechnology.www.yadiudiu.yadiudiu.main.MyApplication;

/**
 * Created by Administrator on 2017/8/15.
 */

public class SharedPreferencesUtil {
    public static class Keys {
        public static final String SEARCH_KEYS = "search_keys";//搜索
        public static final String PASSWORD_KEYS = "password_keys";//密码
        public static final String USERID_KEYS = "userid_keys";//userid
        public static final String TOKEN_KEYS = "token_keys";//token

        public static final String CITY = "city";//token

    }

    private static SharedPreferences sharedPreferences = null;

    /**
     * 取出
     * @param key
     * @param defaultValue
     * @return
     */
    public static String getString(String key, String defaultValue) {
        SharedPreferences sharedPreferences = getSharedPreferences();
        return sharedPreferences.getString(key, defaultValue);
    }

    /**
     *
     * 存放
     * @param key
     * @param value
     */
    public static void putString(String key, String value) {
        SharedPreferences sharedPreferences = getSharedPreferences();
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putString(key, value);
        editor.commit();
    }
    public static synchronized SharedPreferences getSharedPreferences() {
        return getSharedPreferences("ydd");
    }
    public static synchronized SharedPreferences getSharedPreferences(String key) {
        if (sharedPreferences == null) {
            sharedPreferences = MyApplication.getContext().getSharedPreferences(key, Context.MODE_APPEND);
        }
        return sharedPreferences;
    }
}
